# -*- coding: utf-8 -*-
# @Time    : 2024/7/15 15:20
# @Author  : floraachy
# @File    : repo_new_milestone_page
# @Software: PyCharm
# @Desc:

# 标准库导入
# 第三方库导入
import allure
# 本地应用/模块导入
from utils.base_utils.base_page import BasePage


class RepoMilestonePage(BasePage):
    """里程碑列表页面"""
    # 列表所有里程碑名称
    locator_milestone_name_a = "//div[@class='milepostList']//a[contains(@class, 'milepostInfo')]"
    # 列表所有里程碑描述
    locator_milestone_desc_span = "//div[@class='milepostList']//span[contains(@class, 'milepostInfo')]"
    # 列表所有里程碑截止日期
    locator_milestone_deadline_span = "//div[contains(@class, 'effectiveDate')]/i/following-sibling::span"
    # 列表指定的里程碑名称对应的编辑按钮
    locator_edit_btn_by_milestone_name = "//a[contains(@class, 'milepostInfo') and text()='{}']/parent::div/parent::div/following-sibling::div//a[text()='编辑']"
    # 列表指定的里程碑名称对应的删除按钮
    locator_delete_btn_by_milestone_name = "//a[contains(@class, 'milepostInfo') and text()='{}']/parent::div/parent::div/following-sibling::div//a[text()='删除']"
    # 列表指定的里程碑名称对应的开启按钮
    locator_open_btn_by_milestone_name = "//a[contains(@class, 'milepostInfo') and text()='{}']/parent::div/parent::div/following-sibling::div//a[text()='开启']"
    # 列表指定的里程碑名称对应的关闭按钮
    locator_close_btn_by_milestone_name = "//a[contains(@class, 'milepostInfo') and text()='{}']/parent::div/parent::div/following-sibling::div//a[text()='关闭']"
    # 弹窗确认提示的【是】按钮
    locator_yes_btn = "//span[text()='是']"
    # 【已关闭】
    locator_closed_tab = "//span[text()='已关闭']"
    # 【开启中】
    locator_opened_tab = "//span[text()='开启中']"

    @allure.step("访问里程碑列表页：/{repo_owner}/{repo_identifier}/milestones")
    def navigate(self, repo_owner, repo_identifier):
        """
        访问里程碑列表页
        """
        self.visit(f"/{repo_owner}/{repo_identifier}/milestones")

    @allure.step("点击里程碑名称：{milestone_name}对应的编辑按钮")
    def click_edit_btn_by_milestone_name(self, milestone_name):
        """
        点击里程碑名称对应的编辑按钮
        """
        self.click(self.locator_edit_btn_by_milestone_name.format(milestone_name))

    @allure.step("点击里程碑名称：{milestone_name}对应的删除按钮")
    def click_delete_btn_by_milestone_name(self, milestone_name):
        """
        点击里程碑名称对应的删除按钮
        """
        self.click(self.locator_delete_btn_by_milestone_name.format(milestone_name))

    @allure.step("点击里程碑名称：{milestone_name}对应的开启按钮")
    def click_open_btn_by_milestone_name(self, milestone_name):
        """
        点击里程碑名称对应的开启按钮
        """
        self.click(self.locator_open_btn_by_milestone_name.format(milestone_name))

    @allure.step("点击里程碑名称：{milestone_name}对应的关闭按钮")
    def click_close_btn_by_milestone_name(self, milestone_name):
        """
        点击里程碑名称对应的关闭按钮
        """
        self.click(self.locator_close_btn_by_milestone_name.format(milestone_name))

    @allure.step("点击弹窗确认提示的【是】按钮")
    def click_yes_button(self):
        """
        点击弹窗确认提示的【是】按钮
        """
        self.click(self.locator_yes_btn)

    @allure.step("点击【已关闭】tab")
    def click_closed_tab(self):
        """
        点击【已关闭】tab
        """
        self.click(self.locator_closed_tab)

    @allure.step("点击【开启中】tab")
    def click_opened_tab(self):
        """
        点击【开启中】tab
        """
        self.click(self.locator_opened_tab)

    # --------------------- 流程 -------------------------------------
    @allure.step(
        "删除里程碑流程：  里程碑名称：{name}")
    def delete_milestone_flow(self, name):
        """
        删除里程碑流程
        """
        self.click_delete_btn_by_milestone_name(name)
        self.click_yes_button()
